home *** CD-ROM | disk | FTP | other *** search
/ Delphi Informant Complete 1995 - 2000 / Delphi Informant Complete 1995 to 2000.iso / Delphi Informant Magazine Complete Works SOURCE CODE 1998.rar / 1998 / Mar / DI9803DM / CalendarX / CalImpl.pas < prev    next >
Pascal/Delphi Source File  |  1997-12-01  |  8KB  |  314 lines

  1. unit CalImpl;
  2.  
  3. interface
  4.  
  5. uses
  6.   Windows, ActiveX, Classes, Controls, Graphics, Menus, Forms, StdCtrls,
  7.   ComServ, StdVCL, AXCtrls, CalendarX_TLB, Calendar, Grids, AXPropBg;
  8.  
  9. type
  10.   // Descend from TActiveXPropBag to get automatic streaming of properties
  11.   // via IPersistPropertyBag and Delphi's native RTTI
  12.   TCalendarX = class(TActiveXPropBag, ICalendarX)
  13.   private
  14.     { Private declarations }
  15.     FDelphiControl: TCalendar;
  16.     FEvents: ICalendarXEvents;
  17.     procedure ChangeEvent(Sender: TObject);
  18.     procedure ClickEvent(Sender: TObject);
  19.     procedure DblClickEvent(Sender: TObject);
  20.     procedure KeyPressEvent(Sender: TObject; var Key: Char);
  21.   protected
  22.     { Protected declarations }
  23.     procedure InitializeControl; override;
  24.     procedure EventSinkChanged(const EventSink: IUnknown); override;
  25.     procedure DefinePropertyPages(DefinePropertyPage: TDefinePropertyPage); override;
  26.     function Get_BorderStyle: TxBorderStyle; safecall;
  27.     function Get_CalendarDate: TDateTime; safecall;
  28.     function Get_Color: TColor; safecall;
  29.     function Get_Ctl3D: WordBool; safecall;
  30.     function Get_Cursor: Smallint; safecall;
  31.     function Get_Day: Integer; safecall;
  32.     function Get_Enabled: WordBool; safecall;
  33.     function Get_Font: Font; safecall;
  34.     function Get_GridLineWidth: Integer; safecall;
  35.     function Get_Month: Integer; safecall;
  36.     function Get_ParentColor: WordBool; safecall;
  37.     function Get_ReadOnly: WordBool; safecall;
  38.     function Get_StartOfWeek: Smallint; safecall;
  39.     function Get_UseCurrentDate: WordBool; safecall;
  40.     function Get_Visible: WordBool; safecall;
  41.     function Get_Year: Integer; safecall;
  42.     procedure NextMonth; safecall;
  43.     procedure NextYear; safecall;
  44.     procedure PrevMonth; safecall;
  45.     procedure PrevYear; safecall;
  46.     procedure Set_BorderStyle(Value: TxBorderStyle); safecall;
  47.     procedure Set_CalendarDate(Value: TDateTime); safecall;
  48.     procedure Set_Color(Value: TColor); safecall;
  49.     procedure Set_Ctl3D(Value: WordBool); safecall;
  50.     procedure Set_Cursor(Value: Smallint); safecall;
  51.     procedure Set_Day(Value: Integer); safecall;
  52.     procedure Set_Enabled(Value: WordBool); safecall;
  53.     procedure Set_Font(const Value: Font); safecall;
  54.     procedure Set_GridLineWidth(Value: Integer); safecall;
  55.     procedure Set_Month(Value: Integer); safecall;
  56.     procedure Set_ParentColor(Value: WordBool); safecall;
  57.     procedure Set_ReadOnly(Value: WordBool); safecall;
  58.     procedure Set_StartOfWeek(Value: Smallint); safecall;
  59.     procedure Set_UseCurrentDate(Value: WordBool); safecall;
  60.     procedure Set_Visible(Value: WordBool); safecall;
  61.     procedure Set_Year(Value: Integer); safecall;
  62.     procedure UpdateCalendar; safecall;
  63.   end;
  64.  
  65. implementation
  66.  
  67. uses
  68.   CalPage, ComObj, AxTools;
  69.  
  70. { TCalendarX }
  71. procedure TCalendarX.InitializeControl;
  72. begin
  73.   FDelphiControl := Control as TCalendar;
  74.   FDelphiControl.OnChange := ChangeEvent;
  75.   FDelphiControl.OnClick := ClickEvent;
  76.   FDelphiControl.OnDblClick := DblClickEvent;
  77.   FDelphiControl.OnKeyPress := KeyPressEvent;
  78. end;
  79.  
  80. procedure TCalendarX.EventSinkChanged(const EventSink: IUnknown);
  81. begin
  82.   FEvents := EventSink as ICalendarXEvents;
  83. end;
  84.  
  85. procedure TCalendarX.DefinePropertyPages(DefinePropertyPage: TDefinePropertyPage);
  86. begin
  87.   { Define property pages here.  Property pages are defined by calling
  88.     DefinePropertyPage with the class id of the page.  For example,
  89.       DefinePropertyPage(Class_CalendarXPage); }
  90.   DefinePropertyPage(Class_CalendarPage);
  91.   DefinePropertyPage(Class_DFontPropPage);
  92. end;
  93.  
  94. function TCalendarX.Get_BorderStyle: TxBorderStyle;
  95. begin
  96.   Result := Ord(FDelphiControl.BorderStyle);
  97. end;
  98.  
  99. function TCalendarX.Get_CalendarDate: TDateTime;
  100. begin
  101.   Result := FDelphiControl.CalendarDate;
  102. end;
  103.  
  104. function TCalendarX.Get_Color: TColor;
  105. begin
  106.   Result := FDelphiControl.Color;
  107. end;
  108.  
  109. function TCalendarX.Get_Ctl3D: WordBool;
  110. begin
  111.   Result := FDelphiControl.Ctl3D;
  112. end;
  113.  
  114. function TCalendarX.Get_Cursor: Smallint;
  115. begin
  116.   Result := Smallint(FDelphiControl.Cursor);
  117. end;
  118.  
  119. function TCalendarX.Get_Day: Integer;
  120. begin
  121.   Result := FDelphiControl.Day;
  122. end;
  123.  
  124. function TCalendarX.Get_Enabled: WordBool;
  125. begin
  126.   Result := FDelphiControl.Enabled;
  127. end;
  128.  
  129. function TCalendarX.Get_Font: Font;
  130. begin
  131.   GetOleFont(FDelphiControl.Font, Result);
  132. end;
  133.  
  134. function TCalendarX.Get_GridLineWidth: Integer;
  135. begin
  136.   Result := FDelphiControl.GridLineWidth;
  137. end;
  138.  
  139. function TCalendarX.Get_Month: Integer;
  140. begin
  141.   Result := FDelphiControl.Month;
  142. end;
  143.  
  144. function TCalendarX.Get_ParentColor: WordBool;
  145. begin
  146.   Result := FDelphiControl.ParentColor;
  147. end;
  148.  
  149. function TCalendarX.Get_ReadOnly: WordBool;
  150. begin
  151.   Result := FDelphiControl.ReadOnly;
  152. end;
  153.  
  154. function TCalendarX.Get_StartOfWeek: Smallint;
  155. begin
  156.   Result := Smallint(FDelphiControl.StartOfWeek);
  157. end;
  158.  
  159. function TCalendarX.Get_UseCurrentDate: WordBool;
  160. begin
  161.   Result := FDelphiControl.UseCurrentDate;
  162. end;
  163.  
  164. function TCalendarX.Get_Visible: WordBool;
  165. begin
  166.   Result := FDelphiControl.Visible;
  167. end;
  168.  
  169. function TCalendarX.Get_Year: Integer;
  170. begin
  171.   Result := FDelphiControl.Year;
  172. end;
  173.  
  174. procedure TCalendarX.NextMonth;
  175. begin
  176.   FDelphiControl.NextMonth;
  177. end;
  178.  
  179. procedure TCalendarX.NextYear;
  180. begin
  181.   FDelphiControl.NextYear;
  182. end;
  183.  
  184. procedure TCalendarX.PrevMonth;
  185. begin
  186.   FDelphiControl.PrevMonth;
  187. end;
  188.  
  189. procedure TCalendarX.PrevYear;
  190. begin
  191.   FDelphiControl.PrevYear;
  192. end;
  193.  
  194. procedure TCalendarX.Set_BorderStyle(Value: TxBorderStyle);
  195. begin
  196.   FDelphiControl.BorderStyle := TBorderStyle(Value);
  197. end;
  198.  
  199. procedure TCalendarX.Set_CalendarDate(Value: TDateTime);
  200. begin
  201.   FDelphiControl.CalendarDate := Value;
  202. end;
  203.  
  204. procedure TCalendarX.Set_Color(Value: TColor);
  205. begin
  206.   FDelphiControl.Color := Value;
  207. end;
  208.  
  209. procedure TCalendarX.Set_Ctl3D(Value: WordBool);
  210. begin
  211.   FDelphiControl.Ctl3D := Value;
  212. end;
  213.  
  214. procedure TCalendarX.Set_Cursor(Value: Smallint);
  215. begin
  216.   FDelphiControl.Cursor := TCursor(Value);
  217. end;
  218.  
  219. procedure TCalendarX.Set_Day(Value: Integer);
  220. begin
  221.   FDelphiControl.Day := Value;
  222. end;
  223.  
  224. procedure TCalendarX.Set_Enabled(Value: WordBool);
  225. begin
  226.   FDelphiControl.Enabled := Value;
  227. end;
  228.  
  229. procedure TCalendarX.Set_Font(const Value: Font);
  230. begin
  231.   SetOleFont(FDelphiControl.Font, Value);
  232. end;
  233.  
  234. procedure TCalendarX.Set_GridLineWidth(Value: Integer);
  235. begin
  236.   FDelphiControl.GridLineWidth := Value;
  237. end;
  238.  
  239. procedure TCalendarX.Set_Month(Value: Integer);
  240. begin
  241.   FDelphiControl.Month := Value;
  242. end;
  243.  
  244. procedure TCalendarX.Set_ParentColor(Value: WordBool);
  245. begin
  246.   FDelphiControl.ParentColor := Value;
  247. end;
  248.  
  249. procedure TCalendarX.Set_ReadOnly(Value: WordBool);
  250. begin
  251.   FDelphiControl.ReadOnly := Value;
  252. end;
  253.  
  254. procedure TCalendarX.Set_StartOfWeek(Value: Smallint);
  255. begin
  256.   FDelphiControl.StartOfWeek := TDayOfWeek(Value);
  257. end;
  258.  
  259. procedure TCalendarX.Set_UseCurrentDate(Value: WordBool);
  260. begin
  261.   FDelphiControl.UseCurrentDate := Value;
  262. end;
  263.  
  264. procedure TCalendarX.Set_Visible(Value: WordBool);
  265. begin
  266.   FDelphiControl.Visible := Value;
  267. end;
  268.  
  269. procedure TCalendarX.Set_Year(Value: Integer);
  270. begin
  271.   FDelphiControl.Year := Value;
  272. end;
  273.  
  274. procedure TCalendarX.UpdateCalendar;
  275. begin
  276.   FDelphiControl.UpdateCalendar;
  277. end;
  278.  
  279. procedure TCalendarX.ChangeEvent(Sender: TObject);
  280. begin
  281.   if FEvents <> nil then FEvents.OnChange;
  282. end;
  283.  
  284. procedure TCalendarX.ClickEvent(Sender: TObject);
  285. begin
  286.   if FEvents <> nil then FEvents.OnClick;
  287. end;
  288.  
  289. procedure TCalendarX.DblClickEvent(Sender: TObject);
  290. begin
  291.   if FEvents <> nil then FEvents.OnDblClick;
  292. end;
  293.  
  294. procedure TCalendarX.KeyPressEvent(Sender: TObject; var Key: Char);
  295. var
  296.   TempKey: Smallint;
  297. begin
  298.   TempKey := Smallint(Key);
  299.   if FEvents <> nil then FEvents.OnKeyPress(TempKey);
  300.   Key := Char(TempKey);
  301. end;
  302.  
  303. initialization
  304.   // This makes the factory mark this control as "safe"
  305.   TActiveXSafeFactory.Create(
  306.     ComServer,
  307.     TCalendarX,
  308.     TCalendar,
  309.     Class_CalendarX,
  310.     1,
  311.     '',
  312.     0);
  313. end.
  314.